package com.hpf.lease.web.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hpf.lease.common.result.Result;
import com.hpf.lease.model.bean.RoomInfo;
import com.hpf.lease.web.admin.dto.RoomSearchSubmitDto;
import com.hpf.lease.web.admin.dto.RoomSubmitDto;
import com.hpf.lease.web.admin.service.RoomInfoService;
import com.hpf.lease.web.admin.vo.RoomInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/room")
@Tag(name = "房间管理模块")
public class RoomController {
    @Resource
    RoomInfoService roomInfoService;
    @PostMapping("/updateReleaseStatusById")
    @Operation(summary = "修改房间发布状态")
    public Result<Object> updateReleaseStatusById(@RequestParam Integer id ,
                                                  @RequestParam Integer status){
        return Result.build(roomInfoService.update(Wrappers.lambdaUpdate(RoomInfo.class)
                .eq(RoomInfo::getId , id)
                .set(RoomInfo::getIsRelease , status)));
    }
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "保存或更新房间信息")
    public Result<Object> saveOrUpdate(@RequestBody RoomSubmitDto roomSubmitDto){
        return Result.build(roomInfoService.saveOrUpdateInfo(roomSubmitDto));
    }
    @GetMapping("/pageItem")
    @Operation(summary = "条件查询房间信息")
    public Result<Page<RoomInfoVo>> getPageItem(RoomSearchSubmitDto submitDto){
        return Result.ok(roomInfoService.getPageItem(submitDto));
    }
    @GetMapping("/listBasicByApartmentId")
    @Operation(summary = "根据公寓id查询房间列表")
    public Result<List<RoomInfo>> listByApartmentId(@RequestParam long id){
        return Result.ok(roomInfoService.list(Wrappers.lambdaQuery(RoomInfo.class)
                .eq(RoomInfo::getApartmentId , id)));
    }

    @DeleteMapping("/removeById")
    @Operation(summary = "根据id删除房间信息")
    public Result<Object> removeById(@RequestParam long id){
        return Result.build(roomInfoService.removeById(id));
    }
    @GetMapping("/getDetailById")
    @Operation(summary = "根据id获取房间详细信息")
    public Result<RoomInfoVo> getDetailById(@RequestParam long id){
        return Result.ok(roomInfoService.getDetailById(id));
    }
}
